using System;

namespace NEnsure.Rules
{
	public class MaxValueRule<T> : BaseBusinessRule<T>, IBusinessRule<T> where T : IComparable<T>
	{
		private readonly T _maxValue; 

		public override string RuleKey
		{
			get { return "Max-Value Rule"; }
		}

		public MaxValueRule(T maxValue)
			: base("{value} can't be greater than " + maxValue)
		{
			_maxValue = maxValue;
		}

		public bool IsBrokenBy(T value)
		{
			return value.CompareTo(_maxValue) > 0;
		}
	}
}
